const state = {
  contentHeight: 0,
  pageSize: 15,
  userInfo: null, // 用户信息
  serialNumber: '', // 设备序列号
  shiftInfo: null, // 当前班次信息
  autoShowSecondaryScreen: false, // 是否自动打开副屏
  updateMsg: '', // 检查更新提示信息
  reportDialogVisible: false, // 报表弹窗是否显示
  activationDialogVisible: false, //
  posOnlineStatus: true, // pos后台连接状态
  controlOnlineStatus: false, // 中控连接状态
  cardReaderOnlineStatus: false, // 读卡器连接状态
  receiveDialogVisible: false, // 商品领取对话框显示
  secondScreenImageList: [] // 副屏广告图
}

const mutations = {
  TOGGLE_AUTO_SHOW_SECONDARY_SCREEN (state) {
    state.autoShowSecondaryScreen = !state.autoShowSecondaryScreen
  },
  USER_LOGIN (state, payload) {
    state.userInfo = payload
    state.pageSize = 15
  },
  USER_LOGOUT (state) {
    state.userInfo = null
    state.secondScreenImageList = []
  },
  SET_SERIALNUMBER (state, payload) {
    state.serialNumber = payload
  },
  SET_SHIFTINFO (state, payload) {
    state.shiftInfo = payload
  },
  SET_CONTENTHEIGHT (state, data) {
    state.contentHeight = data
  },
  setUpdateMsg (state, data) {
    state.updateMsg = data
  },
  setReportDialogVisible (state, data) {
    state.reportDialogVisible = data
  },
  setActivationDialogVisible (state, data) {
    state.activationDialogVisible = data
  },
  setPosOnlineStatus (state, data) {
    state.posOnlineStatus = data
  },
  setControlOnlineStatus (state, data) {
    state.controlOnlineStatus = data
  },
  setCardReaderOnlineStatus (state, data) {
    state.cardReaderOnlineStatus = data
  },
  setReceiveDialogVisible (state, data) {
    state.receiveDialogVisible = data
  },
  setSecondScreenImageList (state, list) {
    state.secondScreenImageList = list
  }
}

const getters = {
  hasLogin: state => state.userInfo ? !!state.userInfo.stationId : false,
  userName: state => state.userInfo ? state.userInfo.userName : '',
  stationId: state => state.userInfo ? state.userInfo.stationId : '',
  stationName: state => state.userInfo ? state.userInfo.stationName : '',
  permissions: state => state.userInfo ? state.userInfo.permissions : [],
  autoShowSecondaryScreen: state => state.autoShowSecondaryScreen,
  operator: state => state.userInfo ? state.userInfo.loginName + '-' + state.serialNumber : '',
  shiftInfo: state => state.shiftInfo,
  shiftName: state => state.shiftInfo ? state.shiftInfo.shiftName : '',
  token: state => state.userInfo ? state.userInfo.token : '',
  contentHeight: state => state.contentHeight,
  rsaPubKey: state => state.userInfo ? state.userInfo.publicKey : 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuw26SBkq5s8ARzYb3UsIncJWNvLb2Rl8Vd+mwD07sRACdsJm9+3PMxadO4y4MNWo0+CRPmz+qRm6P3RnsztruX2crl0u/sdMv8mQI3zZTzGbZaXgIvrUX0uvOGpgJvuZP+nKxEyawmxC22qgmZ+Vw7ymF13BiQHhS9JPXUQG3LNTVHl7RkH4ROIeNMnnK1e2iRrIsldHcPQ6bc2Zjb4Sais71h3V8H0UOG8Uu/h7cXZ5qnQgYfEJvhveM9bnuLlDQd49I7TbGvNAuqO1wtGDL+DzwTjVIXAaEXGnrg1T3YV+jXIk5zZ3LpdAW8zc/gs1MpgyipJhmzW3P2Cwlq5u0QIDAQAB',
  updateMsg: state => state.updateMsg,
  reportDialogVisible: state => state.reportDialogVisible,
  pageSize: state => state.pageSize,
  activationDialogVisible: state => state.activationDialogVisible,
  posOnlineStatus: state => state.posOnlineStatus,
  controlOnlineStatus: state => state.controlOnlineStatus,
  cardReaderOnlineStatus: state => state.cardReaderOnlineStatus,
  receiveDialogVisible: state => state.receiveDialogVisible,
  secondScreenImageList: state => state.secondScreenImageList,
  userInfo: state => state.userInfo,
  wxServerUrl: state => state.userInfo ? state.userInfo.wxServerUrl : ''
}

const actions = {
  toggleAutoShowSecondaryScreen ({commit}) {
    commit('TOGGLE_AUTO_SHOW_SECONDARY_SCREEN')
  },
  userLogin ({commit}, payload) {
    commit('USER_LOGIN', payload)
  },
  userLogout ({commit}) {
    commit('USER_LOGOUT')
    commit('setUpdateMsg', '')
  },
  setSerialNumber ({commit}, payload) {
    commit('SET_SERIALNUMBER', payload)
  },
  setShiftInfo ({commit}, payload) {
    commit('SET_SHIFTINFO', payload)
  },
  setContentHeight ({commit}, payload) {
    commit('SET_CONTENTHEIGHT', payload)
  },
  setUpdateMsg ({commit}, data) {
    commit('setUpdateMsg', data)
  },
  showReportDialog ({commit}) {
    commit('setReportDialogVisible', true)
  },
  hideReportDialog ({commit}) {
    commit('setReportDialogVisible', false)
  },
  showActivationDialog ({commit}) {
    commit('setActivationDialogVisible', true)
  },
  hideActivationDialog ({commit}) {
    commit('setActivationDialogVisible', false)
  },
  posOnline ({commit}) {
    commit('setPosOnlineStatus', true)
  },
  posOffline ({commit}) {
    commit('setPosOnlineStatus', false)
  },
  controlOnline ({commit}) {
    commit('setControlOnlineStatus', true)
  },
  controlOffline ({commit}) {
    commit('setControlOnlineStatus', false)
  },
  cardReaderOnline ({commit}) {
    commit('setCardReaderOnlineStatus', true)
  },
  cardReaderOffline ({commit}) {
    commit('setCardReaderOnlineStatus', false)
  },
  showReceiveDialog ({commit}) {
    commit('setReceiveDialogVisible', true)
  },
  hideReceiveDialog ({commit}) {
    commit('setReceiveDialogVisible', false)
  },
  setSecondScreenImageList ({commit}, list) {
    commit('setSecondScreenImageList', list)
  }
}
export default {
  state,
  getters,
  mutations,
  actions
}
